package Controls;


import java.util.ArrayList;

import etc.com.market.SpecifyProduct;
import etc.com.market.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class ListitemActivity2 extends Activity implements OnItemClickListener{
    /** Called when the activity is first created. */
	private ListView lv;
	ArrayList<String> arrtext = new ArrayList<String>();
	int[] idimage = new int[6];
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        setContentView(R.layout.listitem);
        
        lv = (ListView)findViewById(R.id.listview);
        lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(this);
        lv.setAdapter(new ImageAdapter(this));
        
        arrtext.add("Food For New Year");
        arrtext.add("Family Event");
        arrtext.add("Sushi");
        arrtext.add("Party Need");
        arrtext.add("Banh xeo");
        arrtext.add("Kim chi");
        
        idimage[0]=R.drawable.ic_launcher;
        idimage[1]=R.drawable.ic_launcher;
        idimage[2]=R.drawable.ic_launcher;
        idimage[3]=R.drawable.ic_launcher;
        idimage[4]=R.drawable.ic_launcher;
        idimage[5]=R.drawable.ic_launcher;
        
    }
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
//		Toast.makeText(this, "CHON:"+arg2, Toast.LENGTH_SHORT).show();
		Intent intent = new Intent(this, SpecifyProduct.class);
		startActivity(intent);
		overridePendingTransition(R.anim.fadein,
                R.anim.fadeout);
	}
	
	public class ImageAdapter extends BaseAdapter{
    	private Context mContext;

        public ImageAdapter(Context c) {
            mContext = c;
        }

        public int getCount() {
            return arrtext.size();
        }

        public Object getItem(int position) {
            return null;
        }

        public long getItemId(int position) {
            return 0;
        }

        // create a new ImageView for each item referenced by the Adapter
        public View getView(int position, View convertView, ViewGroup parent) {
        	LayoutInflater inflater=LayoutInflater.from(mContext);
        	
    		View row=inflater.inflate(R.layout.row, parent, false);
    		
    		ImageView icon=(ImageView)row.findViewById(R.id.iconfile);    		
    		TextView label=(TextView)row.findViewById(R.id.namefile);
    		
    		label.setText(arrtext.get(position));  
//    		label1.setText(arrtext.get(position)); 
			icon.setImageResource(idimage[position]);
			
    		return row;
        }
    }  
}